//
//  BQBottomCarView.m
//  BeeQuick
//
//  Created by mac on 16/11/21.
//  Copyright © 2016年 six_group. All rights reserved.
//

#import "BQBottomCarView.h"
@interface BQBottomCarView()

//选中的按钮
@property (weak, nonatomic) IBOutlet UIButton *isSelectedButton;


//价格
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;

//确认的按钮
@property (weak, nonatomic) IBOutlet UIButton *confirmButton;

//上面那一块的背景View
@property (weak, nonatomic) IBOutlet UIView *topBackgroundView;

//备注的label
@property (weak, nonatomic) IBOutlet UILabel *otherLabel;

@end
@implementation BQBottomCarView

//确认按钮的点击
- (IBAction)comfireButtonClick:(UIButton *)sender {
    
    
    
    [myCar.goodArrM enumerateObjectsUsingBlock:^(BQHomeGoodModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if(obj.Selected )
        {
            [myCar.CurrentGoodArrM addObject:obj];
            NSLog(@"dd");
        }
    }];
    
    
    
    
    if ([self.delegate respondsToSelector:@selector(PushToSumbitOrder:)]) {
        [self.delegate PushToSumbitOrder:sender];
    }
}


//选中按钮的点击
- (IBAction)selectButtonClick:(UIButton *)sender {
    
    NSLog(@"我选中了");

    //车子里面的所有都取反
    
    sender.selected  = !sender.selected;
    
    [myCar.goodArrM enumerateObjectsUsingBlock:^(BQHomeGoodModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        
        obj.Selected = sender.selected;
        
    }];
    
    //单例  刷新
    [myCar reloadMyCarList];
    
    
    
    
}




- (void)setupUI
{
    

}

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    
    //监听showTotalPrice
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(showTotalPrice:) name:@"showTotalPrice" object:nil];
    
    //一开始让 选中按钮 默认为选中
    

    self.isSelectedButton.selected = [myCar isAllSelect];

    
//    
//    //在根据model来判断
//    
//    [myCar.goodArrM enumerateObjectsUsingBlock:^(BQHomeGoodModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//        
//        if(obj.outSelected == NO)
//        {
//            
//        }
//        else
//        {
//            _isSelectedButton.selected = NO;
//            
//        }
//    }];
    
    


    
  
    
    
    
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat totalPrice = [myCar showTotalPrice];
  //取小数点后两位
    self.priceLabel.text = [NSString stringWithFormat:@"%.2f",totalPrice];
    
}


//MARK: -BQShopProductCell 通知实现 .

- (void)showTotalPrice:(NSNotification*)no
{
    
    UIButton *productSelectBtn = no.object;
    
    //把两个选中按钮联动起来
    self.isSelectedButton.selected = myCar.isAllSelect;
    
    CGFloat totalPrice = [myCar showTotalPrice];
    
    //取小数点后两位
    self.priceLabel.text = [NSString stringWithFormat:@"%.2f",totalPrice];
    
    NSLog(@"%@",self.priceLabel.text);
}



- (void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
@end
